﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data;

/// <summary>
/// Summary description for ObtemDDL
/// </summary>
public class ObtemDDL
{
    ConexaoMDBD Command = new ConexaoMDBD();
    
    public ObtemDDL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Boolean GeraDDL(String Empresa, String Ofusca, String Trunca)
    {
        Boolean GeraDDL = false;

        try
        {
            OracleCommand cmdOP = Command.cmdMDBD("PACK_GERA_DDL.SP_GERA_DDL_OWNER");

            cmdOP.Parameters.Add(new OracleParameter("ARG_OWNER", OracleDbType.Varchar2, 255, ParameterDirection.Input)).Value = Empresa;
            cmdOP.Parameters.Add(new OracleParameter("ARG_OFUSCA", OracleDbType.Char, 1, ParameterDirection.Input)).Value = Ofusca;
            cmdOP.Parameters.Add(new OracleParameter("ARG_TRUNC", OracleDbType.Char, 1, ParameterDirection.Input)).Value = Trunca;
            cmdOP.ExecuteNonQuery();

            cmdOP.Connection.Dispose();
            cmdOP.Connection.Close();

            GeraDDL = true;
        }
        catch (Exception e)
        {
            String MensagemErro = e.Message;
        }

        return GeraDDL;
    }

    public DataSet dsListaArquivo(String cmd)
    {
        OracleCommand cmdOP = Command.cmdMDBD(cmd);

        cmdOP.Parameters.Add(new OracleParameter("V_RESULTADO_SAIDA", OracleDbType.RefCursor, ParameterDirection.Output));

        OracleDataAdapter daListaArquivo = new OracleDataAdapter();
        daListaArquivo.SelectCommand = cmdOP;

        DataSet dsListaArquivo = new DataSet();
        daListaArquivo.Fill(dsListaArquivo, "Resultado");

        cmdOP.Connection.Dispose();
        cmdOP.Connection.Close();

        return dsListaArquivo;
    }

    public DataSet dsListaObjeto(String cmd, String TipoObjeto, String Sistema)
    {
        OracleCommand cmdOP = Command.cmdMDBD(cmd);

        cmdOP.Parameters.Add(new OracleParameter("V_NOME_TIPO_OBJT", OracleDbType.Varchar2, 255, ParameterDirection.Input)).Value = TipoObjeto;
        cmdOP.Parameters.Add(new OracleParameter("V_NOME_SIST", OracleDbType.Varchar2, 255, ParameterDirection.Input)).Value = Sistema; 
        cmdOP.Parameters.Add(new OracleParameter("V_RESULTADO_SAIDA", OracleDbType.RefCursor, ParameterDirection.Output));

        OracleDataAdapter daListaObjeto = new OracleDataAdapter();
        daListaObjeto.SelectCommand = cmdOP;

        DataSet dsListaObjeto = new DataSet();
        daListaObjeto.Fill(dsListaObjeto, "ListaObjeto");

        cmdOP.Connection.Dispose();
        cmdOP.Connection.Close();

        return dsListaObjeto;
    }

    public DataSet dsListaTeamProject(String cmd, String Sistema)
    {
        OracleCommand cmdOP = Command.cmdMDBD(cmd);

        cmdOP.Parameters.Add(new OracleParameter("V_NOME_SIST", OracleDbType.Varchar2, 255, ParameterDirection.Input)).Value = Sistema; 
        cmdOP.Parameters.Add(new OracleParameter("V_RESULTADO_SAIDA", OracleDbType.RefCursor, ParameterDirection.Output));

        OracleDataAdapter daListaTeamProject = new OracleDataAdapter();
        daListaTeamProject.SelectCommand = cmdOP;

        DataSet dsListaTeamProject = new DataSet();
        daListaTeamProject.Fill(dsListaTeamProject, "Resultado");

        cmdOP.Connection.Dispose();
        cmdOP.Connection.Close();

        return dsListaTeamProject;
    }

    //public String TextoObjeto(String cmd, String TipoObjeto, String NomeObjeto)
    //{
    //    OracleCommand cmdOP = Command.cmdMDBD(cmd);

    //    cmdOP.Parameters.Add(new OracleParameter("V_RESULTADO_SAIDA", OracleDbType.RefCursor, ParameterDirection.Output));

    //    OracleDataAdapter daResultado = new OracleDataAdapter();
    //    daResultado.SelectCommand = cmdOP;

    //    DataSet dsResultado = new DataSet();
    //    daResultado.Fill(dsResultado, "Resultado");

    //    cmdOP.Connection.Dispose();
    //    cmdOP.Connection.Close();

    //    String TextoObjeto = "";

    //    foreach (DataRow drResultado in dsResultado.Tables[0].Rows)
    //    {

    //    }

    //    return TextoObjeto;
    //}
}
